<?php

namespace Wilead\UserManagerBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface,
    Symfony\Component\Routing\Generator\UrlGeneratorInterface,
    Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\FOSUserEvents,
    FOS\UserBundle\Event\FormEvent;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ChangePasswordSuccessHandle
 *
 * @author jack
 */
class ChangePasswordSuccessHandle implements EventSubscriberInterface {

    private $router;

    public function __construct(UrlGeneratorInterface $router) {
        $this->router = $router;
    }

    public static function getSubscribedEvents() {
        return array(
            FOSUserEvents::CHANGE_PASSWORD_SUCCESS => 'changePasswordSuccess'
        );
    }

    public function changePasswordSuccess(FormEvent $event) {
        $url = $this->router->generate('fos_user_security_logout');
        $event->setResponse(new RedirectResponse($url));
    }

}
